
exports.notEmpty = (ctx) => {
  return (errors, field_name, local, msg) => {
    const field = ctx["request"][local][field_name];
    if (!field || field.length <= 0) {
      errors[field_name] = {
        msg: field_name + " " + (msg || "字段不存在或不能为空"),
        field: field_name,
        local,
      };
    }
    return JSON.stringify(errors) !== "{}" ? errors : false;
  };
};

exports.validatorResult = async (result,ctx, next) => {
  if (JSON.stringify(result) !== "{}" && result) ctx.body = result;
  else await next();
};
